package cn.tedu.hotel.serve.controller;

import cn.tedu.hotel.serve.pojo.entity.secondary.Consult;
import cn.tedu.hotel.serve.service.ISecondaryConsultService;
import cn.tedu.hotel.serve.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/secondaryConsult")
@Api(tags = "08. 咨询管理模块")
public class SecondaryConsultController {
    @Autowired
    ISecondaryConsultService secondaryConsultService;

    @PostMapping("/add-new")
    @ApiOperation("添加咨询")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid Consult consult) {
        log.debug("开始处理【添加咨询】的请求，参数：{}", consult);
        secondaryConsultService.addNew(consult);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据ID删除咨询")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> deleteById(@PathVariable Long id) {
        log.debug("开始处理【根据ID删除咨询】的请求，参数：{}", id);
        secondaryConsultService.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改咨询详情")
    @ApiOperationSupport(order = 300)
    public JsonResult<Void> updateInfoById(@PathVariable Long id,@Valid Consult consult) {
        log.debug("开始处理【修改咨询详情】的请求，新数据：{}",consult);
        secondaryConsultService.updateInfoById(id,consult);
        return JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据ID查询咨询详情")
    @ApiOperationSupport(order = 410)
    public JsonResult<Consult> selectById(@PathVariable Long id) {
        log.debug("开始处理【根据ID查询咨询详情】的请求，参数：{}", id);
        Consult queryResult = secondaryConsultService.getStandardById(id);
        return JsonResult.ok(queryResult);
    }

    @GetMapping("")
    @ApiOperation("查询咨询列表")
    @ApiOperationSupport(order = 420)
    public JsonResult<List<Consult>> select() {
        log.debug("开始处理【查询咨询列表】的请求，无参数");
        List<Consult> list = secondaryConsultService.list();
        return JsonResult.ok(list);
    }
    @PostMapping("/updateView/{id:[0-9]+}")
    public JsonResult<Void> updateViewCountById(@PathVariable Long id) {
        log.debug("开始处理【更新浏览量】的请求，ID：{}", id);
        secondaryConsultService.updateViewCountById(id);
        return JsonResult.ok();
    }
}
